from collections import OrderedDict
from rest_framework.response import Response

from rest_framework.pagination import PageNumberPagination


class CustomPagination(PageNumberPagination):
    """
    最大返回50
    """
    page_size = 20
    page_size_query_param = 'pageSize'
    page_query_param = 'pageNum'
    max_page_size = 50

    def get_paginated_response(self, data):
        # print(self.page.paginator)
        info = {
            'code': 200,
            'message': '操作成功',
            'data': OrderedDict([
                ('list', data),
                ('pageNum', self.page.number),
                ('pageSize', self.page.paginator.per_page),
                ('total', self.page.paginator.count),
                ('totalPage', self.page.paginator.num_pages)
            ])
        }
        return Response(info)
